<template>
    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" background-color="#5c5c64" text-color="#fff"
        active-text-color="#ffd04b" @open="handleOpen" @close="handleClose" :collapse="isShow">
        <h4 class="aside-title">{{isCall}}</h4>
        <!-- 无子菜单 -->
        <el-menu-item v-for="(item,index) in menu" :key="item.path" :index="item.path+''"
            @click="menuClick(item);setTitle(index);changeTitle()">
            <i :class="'el-icon-'+item.icon"></i>
            <p slot="title">{{item.label}}</p>
        </el-menu-item>
    </el-menu>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
    name: 'Aside',
    computed: {
        ...mapState('home', ['isShow', 'menu']),
        //展示时间
        isCall() {
            let hour = new Date().getHours();
            let showTime = '';
            if (5 <= hour && hour < 8) {
                showTime = '早上好！';
            } else if (8 <= hour && hour < 11) {
                showTime = '上午好！';
            } else if (11 <= hour && hour < 13) {
                showTime = '中午好！';
            } else if (13 <= hour && hour < 19) {
                showTime = '下午好！';
            } else if (19 <= hour && hour < 24) {
                showTime = '晚上好！';
            } else {
                showTime = '凌晨了！';
            }
            return this.isShow ? '' : showTime
        }
    },
    methods: {
        //侧边栏组件自带方法
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        //点击导航栏切换路由
        menuClick(item) {
            this.$router.push({
                path: item.path,
            })
        },
        ...mapMutations('home', ['setTitle', 'changeTitle'])
    },
    mounted() {
        //切换头部标题
        this.changeTitle();
    }
}
</script>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 180px;
    min-height: 400px;
    height: 100vh;
}

.aside-title {
    height: 80px;
    color: #fff;
    border: none;
    text-align: center;
    line-height: 80px;
    background-color: "#5c5c64" !important;
}

.el-menu {

    .el-menu-item,
    .el-submenu {
        text-align: left;
    }
}

p{
    display: inline-block;
    width: 85px;
    text-align: center;
}
</style>